import { createApp, reactive } from 'vue'

import myAlert from '@/components/myAlert/myAlert'

const msg = reactive({
    msg: '',
    btn: '',
    show: false,
    btnClick: () => {}
}) 

const alert = createApp(myAlert, {msg}).mount(document.createElement('div'))

// 定义alert消失和出现的方法

const $alert = {
    show(obj) {
        msg.show = true
        msg.msg = obj.msg
        msg.btn = obj.btn
        msg.btnClick = obj.btnClick
        document.body.appendChild(alert.$el)
    },
    hide() {
        msg.show = false
    }
}

export default {
    install(app) {
        app.config.globalProperties.$alert = $alert
    }
}

